#ifndef CAMPAIGN_H
#define CAMPAIGN_H



#include "Item.h"
#include "Attribute.h"
#include "Skill.h"



#include <Serializable.h>



#include <QObject>



class D20_MODELSHARED_EXPORT Campaign : public Item, public Serializable
{

    class Data : public QSharedData
    {
    public:
        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
            items = other.items;
        }

        QHash<quint16, Item*> items;
    };


    Q_OBJECT


public:

    static Campaign* create(const QString& name = QString());
    static Campaign* instance(const QString& name = QString());
    static const QList<Campaign*> all();
    static void destroy(const QString& name);


    virtual void setName(const QString& name);

    Item* createItem(int type, const QString& name);
    void removeItem(int id);

    //Attribute* createAttribute(const QString& name);
    //Skill* createSkill(const QString& name);



    virtual void setSerializedData(const QString& data);
    virtual QString serializedData() const;

    Item* item(const qint32& id);
    QList<Item*> items() const;

    Attribute* attribute(const qint32& id);
    Skill* skill(const qint32& id);

    Attribute* attribute(const QString& name);
    Skill* skill(const QString& name);

    QList<Attribute*> attributes() const;
    QList<Skill*> skills() const;


protected slots:

    virtual void onChanged();
    virtual void onRegenId(const QVariant& old_id);


protected:

    Campaign(QObject* parent = 0);
    Campaign(Campaign& other);

    void addItem(Item* skill);

    // not used
    virtual QVariant bonus();
    virtual QDomElement toXmlElem(QDomElement &elem = QDomElement()) const;
    virtual void fromXmlElem(QDomElement &elem = QDomElement());



private:

    static QList<Campaign*> instances;

    QSharedDataPointer<Data> data;


};






#endif // CAMPAIGN_H
